<template>
    <div id='' class='info_show_list'>
        <div class="tab_show">
            <Tab :list="tab" @onClick="changeTab" :hiddenMore="true" />
        </div>
        <div class="list">
            <div class="item" v-for="(item,index) in list" :key="index" @click="onInfoShow(item)">
                <div class="left">
                    <div class="title" :title="item.title">
                        {{item.title}}
                        <!-- <Ellipsis :text="item.title" :lines="1" tooltip /> -->
                    </div>
                    <div class="describe">{{item.contentStr}}</div>
                </div>
                <div class="right">
                    <div class="type">{{item.releaseDept}}</div>
                    <div class="line">|</div>
                    <div class="time">{{item.releaseDate}}</div>
                </div>
            </div>
        </div>
        <div class="page">
            <Page :total="total" show-total show-sizer show-elevator @on-change='pageChange' @on-page-size-change="changePageSize" />
        </div>

        <Modal v-model="modalShow" width="1200" :mask-closable="false" :title="modalTitle">
            <components v-if="modalShow" :is="comps" ref="coms" @fileInfo='fileInfo' />
            <div slot="footer">
                <div v-if="isShowFileLoad" class="file">
                    <img :src="pdfImg" alt="">
                    <span @click="downLoad()">附件下载</span>
                </div>
                <div class="btn">
                    <Button @click="cancel">关闭</Button>
                    <!-- <Button class="print-btn" type="primary" @click="print">打印</Button> -->
                </div>
            </div>
        </Modal>

    </div>
</template>
<script>
import Tab from '@/pages/fontApp/tab.vue'
import infoModal from './detail.vue'
import pdfImg from '@/assets/svg/fontApp/pdf_icon.svg'
import { UpLoad } from '@/mixins/uploadMixins.js'
export default {
    name: '',
    props: [''],
    data() {
        return {
            modalShow: false,
            modalTitle: '',
            list: [],
            comps: infoModal,
            pdfImg: pdfImg,
            total: 0,
            pageConfig: {
                page: 1,
                limit: 10,
            },
            type: '0',
            tab: [
                { title: '国家法律', default: true },
                { title: '政策解读', default: false },
                { title: '行政法规', default: false },
                { title: '部门规章', default: false },
                { title: '通知公告', default: false },
            ],
            isShowFileLoad: false,
            loadFile: null,
        };
    },
    components: { Tab },
    computed: {},
    beforeMount() { },
    mounted() {
        this.getList();
    },
    mixins: [UpLoad],
    methods: {
        getList() {
            this.$http.$post('InformationReleasePage', { data: { ...this.pageConfig, ...{ type: this.type.split(',') } } }).then(res => {
                if (res.code == 200) {
                    this.list = res.data.records ? res.data.records : [];
                    this.total = Number(res.data.total)
                }
            })
        },
        changeTab(data) {
            let typeObj = {
                '国家法律': '0',
                '政策解读': '1',
                '行政法规': '2',
                '部门规章': '3',
                '通知公告': '4,5',
            }
            this.pageConfig.page = 1;
            this.type = typeObj[data.title];
            this.getList(this.type);
        },
        onInfoShow(event) {
            this.modalShow = true;
            this.isShowFileLoad = false;
            this.$nextTick(() => {
                let typeObj = {
                    '0': '国家法律',
                    '1': '政策解读',
                    '2': '行政法规',
                    '3': '部门规章',
                    '4,5': '通知公告',
                }
                this.$refs.coms.getInfo(event.id, typeObj[this.type])
            })
            // this.$router.push({
            //     path: `/detailInfo/index/信息公开`,
            //     query: {
            //         id: event.id,
            //     }
            // })
        },
        // 页码改变
        pageChange(page) {
            this.pageConfig.page = page;
            this.getList()
        },
        // 每页条数改变
        changePageSize(pageSize) {
            this.pageConfig.limit = pageSize;
            this.getList()
        },

        cancel() {
            this.modalShow = false
        },

        fileInfo(file) {
            if (file) {
                this.isShowFileLoad = true;
                this.loadFile = file;
            }
        },
        downLoad() {
            this.downloadUrl(this.loadFile.minioPath, this.loadFile);
        },
        print() {
            this.$refs.coms.print()
            // const printHTML = document.querySelector('#aaaaa').innerHTML
            // // 将打印的区域赋值，进行打印
            // window.document.body.innerHTML = printHTML
            // window.print() // 调用window打印方法
            // window.location.reload() // 打印完成后重新加载页面
        },
    },
    watch: {}
}
</script>
<style lang='less' scoped>
.info_show_list {
    .tab_show {
        margin-top: 20px;
    }
    .list {
        padding: 1px 0 40px 0;
        height: 500px;
        overflow: auto;
        .item {
            padding: 20px 0;
            display: flex;
            border-bottom: 1px solid #edeef0;
            cursor: pointer;
            .left {
                width: 1020px;
                display: flex;
                flex-direction: column;
                justify-content: space-around;
                .title {
                    font-size: 16px;
                    font-family: PingFang SC-Bold, PingFang SC;
                    font-weight: bold;
                    color: #17233d;
                    word-break: break-all;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    -o-text-overflow: ellipsis;
                }
                .describe {
                    font-size: 16px;
                    font-family: PingFang SC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #808695;
                }
            }
            .right {
                width: 200px;
                display: flex;
                justify-content: space-around;
                .time {
                    font-size: 16px;
                    font-family: PingFang SC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #808695;
                }
                .line {
                    margin-bottom: 1px;
                    color: #dcdee2;
                }
                .type {
                    width: 90px;
                    display: flex;
                    justify-content: flex-end;
                    font-size: 16px;
                    font-family: PingFang SC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #17233d;
                }
            }
        }
        .item:first-child {
            border-top: 1px solid #edeef0;
        }
    }
    .page {
        height: 58px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
}
.file {
    cursor: pointer;
    text-align: left;
    img {
        width: 16px;
    }
    span {
        margin-left: 10px;
        font-size: 16px;
        font-family: PingFang SC-Regular, PingFang SC;
        font-weight: 400;
        color: #3399ff;
    }
}
.btn {
    // text-align: center;
    // .print-btn {
    //     margin-left: 20px;
    // }
}
</style>